﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using System.IO;

public partial class SpecialPlan_NoVerifySpecialPlan : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        this.btnOk.Visible = false;
        _powerTable = dllAuthentication.getPower(objUserInfo.UserName, "待处理专项计划");
        for (int i = 0; i < _powerTable.Rows.Count; i++)
        {
            if (_powerTable.Rows[i]["PowerName"].ToString() == "新建")
            {
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "删除")
            {
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "查看")
            {
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "修改")
            {
                this.btnOk.Visible = true;
            }
        }


        if (!IsPostBack)
        {
            #region 弹出提醒
            PopupManager dllPopupManager = new PopupManager();
            string _info = dllPopupManager.getPopupInfo();
            if (_info.Length > 0)
            {
                ShowMessage(_info);
            }
            #endregion

            if (Request.Params["type"] != null && Request.Params["type"].ToString().Length != 0)
            {
                this.drpType.SelectedIndex = this.drpType.Items.IndexOf(this.drpType.Items.FindByValue(Request.Params["type"].ToString()));
            }
            if (this.drpType.SelectedItem.Value == "0")
            {
                //绑定待评估
                bindGridViewCheckNote();
                this.gdvNoVerifySpecialPlan.Visible = false;
                this.btnOk.Visible = false;
                this.btnVerifyCircuit.Visible = true;
                this.btnReturn.Visible = false;
                this.divNoVerifySpecialPlan.Visible = false;
                this.divEvaluteCheckNote.Visible = true;
            }
            else
            {
                //绑定是否达成共识
                bindGridView();
                this.gdvEvaluteCheckNote.Visible = false;
                this.btnOk.Visible = true;
                this.btnVerifyCircuit.Visible = true;
                this.btnReturn.Visible = true;
                this.divNoVerifySpecialPlan.Visible = true;
                this.divEvaluteCheckNote.Visible = false;
            }
        }
    }


    /// <summary>
    /// 弹出小窗体事件
    /// </summary>
    /// <param name="msg"></param>
    public void ShowMessage(string msg)
    {
        EeekSoft.Web.PopupWin pop = new EeekSoft.Web.PopupWin();
        this.Controls.Add(pop);
        pop.Text = msg;
        pop.Message = msg;
        pop.Title = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
        pop.WindowScroll = true;
        pop.HideAfter = 99999999;
        pop.DockMode = EeekSoft.Web.PopupDocking.BottomLeft;
        pop.OffsetX = int.Parse(Session["_width"].ToString()) - 338;
        pop.ActionType = EeekSoft.Web.PopupAction.MessageWindow;
        pop.OffsetY = 1;
        pop.Width = 220;
        pop.Height = 170;
    }


    /// <summary>
    /// 绑定是否达成共识GridView（处理待评估、待审核计划）
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    void bindGridView()
    {
        object[] _value = new object[1];
        Model.UserInfo objUserInfo = new Model.UserInfo();
        _value[0] = objUserInfo.UserName;


        DataView dv = new DataView(new BLL.SpecialPlan().getSpecialPlanNoEvaluateAndNoVerify(_value));
        dv.Sort = "SpecialPlanSortId";
        this.gdvNoVerifySpecialPlan.DataSource = dv;
        this.gdvNoVerifySpecialPlan.DataBind();
        this.rptNoVerifySpecialPlan.DataSource = dv;
        this.rptNoVerifySpecialPlan.DataBind();
        #region
        for (int i = 0; i < gdvNoVerifySpecialPlan.Rows.Count; i++)
        {
            wrapByComma(this.gdvNoVerifySpecialPlan, i, 8);
            TextBox tb = (TextBox)this.gdvNoVerifySpecialPlan.Rows[i].Cells[12].FindControl("txtVerifyPeopleOpinion");
            tb.Text = this.gdvNoVerifySpecialPlan.DataKeys[i]["EvaluatePeopleVerifyOpinion"].ToString();
            if (Convert.ToInt32(this.gdvNoVerifySpecialPlan.DataKeys[i]["PlanSendState"]) == 2)
            {
                tb.Attributes.Add("readonly", "true");
            }
            else
            {
                tb.Enabled = true;
            }
            //文件下载，判断如果下载了就显示《下载按钮》 反之 就显示“无下载”
            if (gdvNoVerifySpecialPlan.DataKeys[i]["AttachmengPath"].ToString().Length == 0)
            {
                Button _btn = (Button)gdvNoVerifySpecialPlan.Rows[i].Cells[12].FindControl("btnDownLoad");
                _btn.Visible = false;
                Label _lbl = (Label)gdvNoVerifySpecialPlan.Rows[i].Cells[12].FindControl("lblAlert");
                _lbl.Visible = true;
                _lbl.Text = "无下载";
            }
        }

        #endregion
    }




    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }


    /// <summary>
    /// 下载附件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvNoVerifySpecialPlan.DataKeys[i]["AttachmengPath"].ToString();
        FileDownload(path);
        //Utility.HttpHelp.DownloadFile(path);
    }

    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {
        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();
    }


    protected void btnDownLoad1_Click(object sender, EventArgs e)
    {

        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvEvaluteCheckNote.DataKeys[i]["AttachmengPath"].ToString();
        FileDownload(path);
    }



    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    public string wrapByComma(string str)
    {
        string _content = string.Empty;
        _content = str.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _content = str.Replace(",", "<br>");
        return _content;

    }

    /// <summary>
    /// 修改计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMofify_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _SpecialPlanId = 0;
        #region
        //for (int i = 0; i < this.gdvNoVerifySpecialPlan.Rows.Count; i++)
        //{
        //    CheckBox ckb = (CheckBox)this.gdvNoVerifySpecialPlan.Rows[i].Cells[0].FindControl("ckbSelect");
        //    if (ckb.Checked == true)
        //    {
        //        _SpecialPlanId = Convert.ToInt32(this.gdvNoVerifySpecialPlan.DataKeys[i]["Id"].ToString());
        //        _count++;
        //    }
        //}
        #endregion
        foreach (RepeaterItem i in this.rptNoVerifySpecialPlan.Items)
        {
            CheckBox cbox = (CheckBox)i.FindControl("ckbSelect");
            if (cbox.Checked == true)
            {
                _SpecialPlanId = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanId")).Value);
                _count++;
            }
        }
        //判断上部GridView是否有选中计划
        if (_count == 1)
        {
            //判断是否计划二次评估完成， 评估完成不允许修改。
            object[] _value = new object[1];
            _value[0] = _SpecialPlanId;
            DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(_value);
            if (SpecialPlan.Rows.Count == 0)
            {
                if (Convert.ToInt32(SpecialPlan.Rows[0]["State"]) >= 4)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否评估人
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = new BLL.UserInfoManager().get(UserInfoManager.field.UserName.ToString(), _user);

            if (_userTable.Rows.Count > 0)
            {
                if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() != _userTable.Rows[0]["RealName"].ToString())
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    string _url = "ModifySpecialPlan.aspx?Id=" + _SpecialPlanId + "&url=NoVerifySpecialPlan.aspx";
                    Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                    return;

                }
            }
        }
        else
        {
            //循环下部Gridview判断计划是否选中
            for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvEvaluteCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    _SpecialPlanId = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["Id"].ToString());
                    _count++;
                }
            }
            if (_count == 1)
            { //判断是否计划二次评估完成， 评估完成不允许修改。
                object[] _value = new object[1];
                _value[0] = _SpecialPlanId;
                DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(_value);
                if (SpecialPlan.Rows.Count == 0)
                {
                    if (Convert.ToInt32(SpecialPlan.Rows[0]["State"]) >= 4)
                    {
                        Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                        return;
                    }
                }
                //判断是否评估人
                Model.UserInfo objUser = new Model.UserInfo();
                object[] _user = new object[1];
                _user[0] = objUser.UserName;
                DataTable _userTable = new BLL.UserInfoManager().get(UserInfoManager.field.UserName.ToString(), _user);

                if (_userTable.Rows.Count > 0)
                {
                    if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() == _userTable.Rows[0]["RealName"].ToString())
                    {
                        Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                    }
                    else
                    {
                        string _url = "ModifySpecialPlan.aspx?Id=" + _SpecialPlanId + "&url=NoVerifySpecialPlan.aspx";
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;

                    }
                }
            }
            if (_count > 1)
            {
                Utility.HttpHelp.alert("只能修改一个计划", Page);
                return;
            }
            if (_count == 0)
            {
                Utility.HttpHelp.alert("请选择一个计划", Page);
                return;
            }
        }
    }


    /// <summary>
    /// 查看分解事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMonthResolve_Click(object sender, EventArgs e)
    {
        int i = 0;
        int _count = 0;

        int _SpecialPlanId = 0;
        for (int k = 0; k < this.gdvEvaluteCheckNote.Rows.Count; k++)
        {
            CheckBox ckb = (CheckBox)gdvEvaluteCheckNote.Rows[k].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (ckb.Checked == true)
                {
                    if (gdvEvaluteCheckNote.DataKeys[k]["Id"] != null && gdvEvaluteCheckNote.DataKeys[k]["Id"].ToString().Length != 0)
                    {
                        _SpecialPlanId = Convert.ToInt32(gdvEvaluteCheckNote.DataKeys[k]["Id"].ToString());
                        _count++;
                    }
                }
            }
        }
        for (int k = 0; k < this.gdvNoVerifySpecialPlan.Rows.Count; k++)
        {
            CheckBox ckb = (CheckBox)gdvNoVerifySpecialPlan.Rows[k].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (ckb.Checked == true)
                {
                    if (gdvNoVerifySpecialPlan.DataKeys[k]["Id"] != null && gdvNoVerifySpecialPlan.DataKeys[k]["Id"].ToString().Length != 0)
                    {
                        _SpecialPlanId = Convert.ToInt32(gdvNoVerifySpecialPlan.DataKeys[k]["Id"].ToString());
                        _count++;
                    }
                }
            }
        }
        if (_count == 1)
        {
            string _url = "SpecialPlanResolveAdd.aspx?SpecialPlanId=" + _SpecialPlanId;
            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1100,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
            return;
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个专项计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }

    }


    /// <summary>
    /// 退回事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        //根据评估人查询当前用户的待审专项计划
        //判断是否评估人
        object[] _user = new object[1];
        _user[0] = objUserInfo.UserName;
        DataTable _userTable = new BLL.UserInfoManager().get(UserInfoManager.field.UserName.ToString(), _user);

        if (_userTable.Rows.Count > 0)
        {
            int _count = 0;
            List<object[]> _valueList = new List<object[]>();
            object[] _username = new object[2];
            #region
            for (int i = 0; i < this.gdvNoVerifySpecialPlan.Rows.Count; i++)
            {
                string a = this.gdvNoVerifySpecialPlan.Rows[i].Cells[2].Text;
                CheckBox ckb = (CheckBox)this.gdvNoVerifySpecialPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    object[] _value = new object[2];
                    _value[0] = Convert.ToInt32(this.gdvNoVerifySpecialPlan.DataKeys[i]["Id"].ToString());
                    //主管领导不需要修改审核意见
                    _username[0] = _userTable.Rows[0]["RealName"].ToString();
                    _username[1] = Convert.ToInt32(this.gdvNoVerifySpecialPlan.DataKeys[i]["Id"].ToString());
                    DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(new object[] { _value[0] });
                    TextBox tb = (TextBox)this.gdvNoVerifySpecialPlan.Rows[i].FindControl("txtVerifyPeopleOpinion");
                    if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() == _userTable.Rows[0]["RealName"].ToString())
                    {
                        _value[1] = SpecialPlan.Rows[0]["CheckNote"].ToString();
                    }
                    else
                    {
                        if (tb.Text.Length < 18)
                        {
                            Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                            return;
                        }
                        _value[1] = tb.Text;
                    }
                    _value[1] = tb.Text;
                    _valueList.Add(_value);
                    _count++;
                }
            }
            #endregion
            foreach (RepeaterItem i in this.rptNoVerifySpecialPlan.Items)
            {
                CheckBox cbox = (CheckBox)i.FindControl("ckbSelect");
                if (cbox.Checked == true)
                {
                    object[] _value = new object[2];
                    _value[0] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanId")).Value);
                    //主管领导不需要修改审核意见
                    _username[0] = _userTable.Rows[0]["RealName"].ToString();
                    _username[1] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanId")).Value);
                    DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(new object[] { _value[0] });
                    TextBox tb = (TextBox)i.FindControl("txtVerifyPeopleOpinion");
                    if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() != _userTable.Rows[0]["RealName"].ToString())
                    {
                        _value[1] = SpecialPlan.Rows[0]["CheckNote"].ToString();
                    }
                    else
                    {
                        if (tb.Text.Length < 18)
                        {
                            Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                            return;
                        }
                        _value[1] = tb.Text;
                    }
                    _value[1] = tb.Text;
                    _valueList.Add(_value);
                    _count++;
                }
            }
            if (_count == 0)
            {
                Utility.HttpHelp.alert("请至少选择一个计划", Page);
                return;
            }
            int result = new BLL.SpecialPlan().EditSpecialPlanReturnByIdWithTranscation(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("提交计划评估人评估未成功，请重试！");
            }
            else
            {
                Response.Redirect("NoVerifySpecialPlan.aspx");
            }
        }

    }
    /// <summary>
    /// 通过事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        object[] _user = new object[1];
        _user[0] = objUserInfo.UserName;
        DataTable _userTable = new BLL.UserInfoManager().get(UserInfoManager.field.UserName.ToString(), _user);

        if (_userTable.Rows.Count > 0)
        {
            int _count = 0;
            List<object[]> _valueList = new List<object[]>();
            object[] _username = new object[2];
            #region
            //for (int i = 0; i < this.gdvNoVerifySpecialPlan.Rows.Count; i++)
            //{
            //    string a = this.gdvNoVerifySpecialPlan.Rows[i].Cells[2].Text;
            //    CheckBox ckb = (CheckBox)this.gdvNoVerifySpecialPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            //    if (ckb.Checked == true)
            //    {
            //        object[] _value = new object[3];
            //        _value[0] = Convert.ToInt32(this.gdvNoVerifySpecialPlan.DataKeys[i]["Id"].ToString());
            //        _value[1] = objUserInfo.UserName;
            //        //主管领导不需要修改审核意见
            //        _username[0] = _userTable.Rows[0]["RealName"].ToString();
            //        _username[1] = Convert.ToInt32(this.gdvNoVerifySpecialPlan.DataKeys[i]["Id"].ToString());
            //        DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(new object[] { _value[0] });
            //        TextBox tb = (TextBox)this.gdvNoVerifySpecialPlan.Rows[i].FindControl("txtVerifyPeopleOpinion");
            //        if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() == _userTable.Rows[0]["RealName"].ToString())
            //        {
            //            _value[2] = "";
            //        }
            //        else
            //        {
            //            if (tb.Text.Length < 18)
            //            {
            //                Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
            //                return;
            //            }
            //            _value[2] = tb.Text;
            //        }
            //        _valueList.Add(_value);
            //        _count++;
            //    }
            //}
            #endregion
            foreach (RepeaterItem i in this.rptNoVerifySpecialPlan.Items)
            {
                CheckBox cbox = (CheckBox)i.FindControl("ckbSelect");
                if (cbox.Checked == true)
                {
                    object[] _value = new object[3];
                    _value[0] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanId")).Value);
                    _value[1] = objUserInfo.UserName;
                    //主管领导不需要修改审核意见
                    _username[0] = _userTable.Rows[0]["RealName"].ToString();
                    _username[1] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanId")).Value);
                    DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(new object[] { _value[0] });
                    TextBox tb = (TextBox)i.FindControl("txtVerifyPeopleOpinion");
                    if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() != _userTable.Rows[0]["RealName"].ToString())
                    {
                        _value[2] = "";
                    }
                    else
                    {
                        if (tb.Text.Length < 18)
                        {
                            Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                            return;
                        }
                        _value[2] = tb.Text;
                    }
                    _valueList.Add(_value);
                    _count++;
                }
            }

            if (_count == 0)
            {
                Utility.HttpHelp.alert("请至少选择一个专项计划", Page);
                return;
            }
            if (this.drpType.SelectedItem.Text != null && this.drpType.SelectedItem.Value == "1")
            {
                //修改发送状态为2，进入审核流程
                int result = new BLL.SpecialPlan().EditSpecialPlanOkByIdWithTranscation(_valueList);
                if (result == 0)
                {
                    Utility.Error.RedirectErrorPage("提交计划评估未成功，请重试！");
                }
                else
                {
                    Response.Redirect("NoVerifySpecialPlan.aspx");
                }
            }
        }
    }


    /// <summary>
    /// 全选事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ckbAllSelect_CheckedChanged(object sender, EventArgs e)
    {
        if (ckbAllSelect.Checked == true)
        {
            //for (int i = 0; i < this.gdvNoVerifySpecialPlan.Rows.Count; i++)
            //{
            //    CheckBox ckb = (CheckBox)this.gdvNoVerifySpecialPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            //    ckb.Checked = true;
            //}
            foreach (RepeaterItem i in this.rptNoVerifySpecialPlan.Items)
            {
                CheckBox ckb = (CheckBox)i.FindControl("ckbSelect");
                ckb.Checked = true;
            }
        }
        else
        {
            //for (int i = 0; i < this.gdvNoVerifySpecialPlan.Rows.Count; i++)
            //{
            //    CheckBox ckb = (CheckBox)this.gdvNoVerifySpecialPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            //    ckb.Checked = false;
            //}
            foreach (RepeaterItem i in this.rptNoVerifySpecialPlan.Items)
            {
                CheckBox ckb = (CheckBox)i.FindControl("ckbSelect");
                ckb.Checked = false;
            }
        }
    }
    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvNoVerifySpecialPlan_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvNoVerifySpecialPlan.PageIndex = e.NewPageIndex;
        bindGridView();
    }



    /// <summary>
    /// 类型改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpType.SelectedItem.Value == "0")
        {
            //绑定待评估
            bindGridViewCheckNote();
            this.gdvNoVerifySpecialPlan.Visible = false;
            this.gdvEvaluteCheckNote.Visible = false;
            this.btnOk.Visible = false;
            this.btnReturn.Visible = false;
            this.btnVerifyCircuit.Visible = true;
            this.hType.Value = "0";
            this.divNoVerifySpecialPlan.Visible = false;
            this.divEvaluteCheckNote.Visible = true;

        }
        else
        {
            //绑定是否达成共识
            bindGridView();
            this.gdvEvaluteCheckNote.Visible = false;
            this.gdvNoVerifySpecialPlan.Visible = false;
            this.btnOk.Visible = true;
            this.btnReturn.Visible = true;
            this.btnVerifyCircuit.Visible = true;
            this.hType.Value = "1";
            this.divNoVerifySpecialPlan.Visible = true;
            this.divEvaluteCheckNote.Visible = false;

        }
    }

    /// <summary>
    /// 绑定待评估GridView
    /// </summary>
    void bindGridViewCheckNote()
    {
        //根据评估人查询当前用户的待最后一次评估的计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        object[] _value = new object[1];
        _value[0] = objUserInfo.UserName;
        DataView dv = new DataView(new BLL.SpecialPlan().getSpecialPlanEvaluatedAndVerified(_value));
        dv.Sort = "SpecialPlanSortId";
        //this.gdvEvaluteCheckNote.DataSource = dv;
        //this.gdvEvaluteCheckNote.DataBind();
        this.rptEvaluteCheckNote.DataSource = dv;
        this.rptEvaluteCheckNote.DataBind();

        #region 截取字符串
        for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
        {
            wrapByComma(this.gdvEvaluteCheckNote, i, 8);
            DropDownList drp = (DropDownList)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
            drp.SelectedValue = this.gdvEvaluteCheckNote.DataKeys[i]["State"].ToString();
            if (Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["State"].ToString()) > 3)
            {
                Button btn = (Button)this.gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("btnTiJiao");
                btn.Enabled = false;
            }
            if (gdvEvaluteCheckNote.DataKeys[i]["AttachmengPath"].ToString().Length == 0)
            {
                Button _btn = (Button)gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("btnDownLoad1");
                _btn.Visible = false;
                Label _lbl = (Label)gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("lblAlert1");
                _lbl.Visible = true;
                _lbl.Text = "无下载";
            }
        }
        #endregion
    }


    /// <summary>
    /// 评估意见提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnTiJiao_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        DropDownList drp = (DropDownList)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
        ListItem _li = drp.SelectedItem;

        if (_li != null)
        {
            if (_li.Text != "请选择")
            {
                object[] _value = new object[3];
                _value[0] = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["Id"].ToString());
                TextBox tb = (TextBox)this.gdvEvaluteCheckNote.Rows[i].Cells[14].FindControl("txtCheckNote");
                if (tb.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("评估意见不得少于32个字符", Page);
                    return;
                }
                tb.Text = tb.Text + "\r\n";
                _value[1] = tb.Text;
                _value[2] = Convert.ToInt32(_li.Value);
                //填写checknote字段内容（追加）
                int result = new BLL.SpecialPlan().EditSpecialPlanEvaluate(_value);
                if (result == 0)
                {
                    Utility.Error.RedirectErrorPage("提交评估意见未成功，请重试！");
                }
                else
                {
                    bindGridViewCheckNote();
                }
            }
            else
            {
                Utility.HttpHelp.alert("请选择计划完成状态", Page);
            }
        }
    }


    /// <summary>
    /// 查看流程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnVerifyCircuit_Click(object sender, EventArgs e)
    {
        int _count = 0;
        string _url = "";
        int _SpecialPlanId = 0;
        #region
        //for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
        //{
        //    CheckBox chk = (CheckBox)this.gdvEvaluteCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
        //    if (chk.Checked == true)
        //    {
        //        _count++;
        //        _SpecialPlanId = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["Id"].ToString());

        //    }
        //}

        //for (int i = 0; i < this.gdvNoVerifySpecialPlan.Rows.Count; i++)
        //{
        //    CheckBox chk = (CheckBox)this.gdvNoVerifySpecialPlan.Rows[i].Cells[0].FindControl("ckbSelect");
        //    if (chk.Checked == true)
        //    {
        //        _count++;
        //        _SpecialPlanId = Convert.ToInt32(this.gdvNoVerifySpecialPlan.DataKeys[i]["Id"].ToString());

        //    }
        //}
        #endregion
        foreach (RepeaterItem i in this.rptNoVerifySpecialPlan.Items)
        {
            CheckBox cbox = (CheckBox)i.FindControl("ckbSelect");
            if (cbox.Checked == true)
            {
                _count++;
                _SpecialPlanId = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanId")).Value);
            }
        }
        foreach (RepeaterItem i in this.rptEvaluteCheckNote.Items)
        {
            CheckBox cbox = (CheckBox)i.FindControl("ckbSelect");
            if (cbox.Checked == true)
            {
                _count++;
                _SpecialPlanId = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanId")).Value);
            }
        }


        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
        if (_count == 1)
        {
            _url = "../WebCommon/VerifyCircruitDisplay.aspx?PlanId=" + _SpecialPlanId + "&PlanType=6";
            Page.RegisterStartupScript("windowOpen",
               "<script language=javascript>window.open('" + _url + "','newwindow','height=150,width=550,top=250,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }

    }



    /// <summary>
    /// reapeater事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptEvaluteCheckNote_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        //提交
        if (e.CommandName == "TiJiao")
        {
            int Id = Convert.ToInt32(e.CommandArgument);
            DropDownList drp = e.Item.FindControl("dropZhuangTai") as DropDownList;
            if (drp.SelectedItem != null)
            {
                if (drp.SelectedItem.Text != "请选择")
                {
                    object[] _value = new object[3];
                    _value[0] = Id;
                    TextBox tb = e.Item.FindControl("txtCheckNote") as TextBox;
                    if (tb.Text.Length < 18)
                    {
                        Utility.HttpHelp.alert("评估意见不得少于32个字符", Page);
                        return;
                    }
                    tb.Text = tb.Text + "\r\n";
                    _value[1] = tb.Text;
                    _value[2] = Convert.ToInt32(drp.SelectedItem.Value);
                    //填写checknote字段内容（追加）
                    int result = new BLL.SpecialPlan().EditSpecialPlanEvaluate(_value);
                    if (result == 0)
                    {
                        Utility.Error.RedirectErrorPage("提交评估意见未成功，请重试！");
                    }
                    else
                    {
                        bindGridViewCheckNote();
                    }
                }
                else
                {
                    Utility.HttpHelp.alert("请选择计划完成状态", Page);
                }
            }
        }
    }

    /// <summary>
    /// reapeater事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptEvaluteCheckNoteDetail_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        //提交
        if (e.CommandName == "TiJiao")
        {
            int Id = Convert.ToInt32(e.CommandArgument);
            DropDownList drp = e.Item.FindControl("dropZhuangTai") as DropDownList;
            if (drp.SelectedItem != null)
            {
                if (drp.SelectedItem.Text != "请选择")
                {
                    object[] _value = new object[3];
                    _value[0] = Id;
                    TextBox tb = e.Item.FindControl("txtCheckNote") as TextBox;
                    if (tb.Text.Length < 18)
                    {
                        Utility.HttpHelp.alert("评估意见不得少于32个字符", Page);
                        return;
                    }
                    tb.Text = tb.Text + "\r\n";
                    _value[1] = tb.Text;
                    _value[2] = Convert.ToInt32(drp.SelectedItem.Value);
                    //填写checknote字段内容（追加）
                    int result = new BLL.SpecialPlan().EditSpecialPlanDetailEvaluate(_value);
                    if (result == 0)
                    {
                        Utility.Error.RedirectErrorPage("提交评估意见未成功，请重试！");
                    }
                    else
                    {
                        bindGridViewCheckNote();
                    }
                }
                else
                {
                    Utility.HttpHelp.alert("请选择计划完成状态", Page);
                }
            }
        }
    }

    /// <summary>
    /// 待二次评估专项计划绑定
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptEvaluteCheckNote_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField HSpecialPlanId = e.Item.FindControl("HSpecialPlanId") as HiddenField;
            Repeater rep = e.Item.FindControl("rptEvaluteCheckNoteDetail") as Repeater;//找到里层的repeater对象
            Label lblAlert = e.Item.FindControl("lblAlert") as Label;
            Button btnDownLoad = e.Item.FindControl("btnDownLoad") as Button;
            HiddenField HAttachmengPath = e.Item.FindControl("HAttachmengPath") as HiddenField;
            DropDownList dropZhuangTai = e.Item.FindControl("dropZhuangTai") as DropDownList;
            HiddenField HState = e.Item.FindControl("HState") as HiddenField;
            HiddenField HEvaluatePeople = e.Item.FindControl("HEvaluatePeople") as HiddenField;
            Button btnTiJiao = e.Item.FindControl("btnTiJiao") as Button;
            if (HAttachmengPath.Value.Length > 0)
            {
                lblAlert.Visible = false;
                btnDownLoad.Visible = true;
            }
            else
            {
                lblAlert.Visible = true;
                btnDownLoad.Visible = false;
            }
            DataTable dt = new BLL.UserInfoManager().get(BLL.UserInfoManager.field.UserName.ToString(), new object[] { objUserInfo.UserName });
            if (dt.Rows.Count > 0)
            {
                if (Convert.ToInt32(HState.Value) == 3 && HEvaluatePeople.Value == dt.Rows[0]["RealName"].ToString())
                {
                    dropZhuangTai.Enabled = true;
                    btnTiJiao.Enabled = true;
                }
                else
                {
                    dropZhuangTai.Enabled = false;
                    btnTiJiao.Enabled = false;
                }
            }


            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(HSpecialPlanId.Value);
            rep.DataSource = new BLL.SpecialPlan().GetSpecialPlanDetailBySpecialId(_value);
            rep.DataBind();
        }
    }

    /// <summary>
    /// 待二次评估专项计划明细绑定
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptEvaluteCheckNoteDetail_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField HSpecialPlanDetailId = e.Item.FindControl("HSpecialPlanDetailId") as HiddenField;
            HiddenField HState = e.Item.FindControl("HState") as HiddenField;
            DropDownList drp = e.Item.FindControl("dropZhuangTai") as DropDownList;
            TextBox tb = e.Item.FindControl("txtCheckNote") as TextBox;
            Button btn = e.Item.FindControl("btnTiJiao") as Button;
            if (Convert.ToInt32(HState.Value) == 3)
            {
                drp.Enabled = true;
                tb.Enabled = true;
                btn.Enabled = true;
            }
            else
            {
                drp.Enabled = false;
                tb.Enabled = false;
                btn.Enabled = false;
            }

        }
    }


    /// <summary>
    /// 待审核Reapeater绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptNoVerifySpecialPlan_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField HSpecialPlanId = e.Item.FindControl("HSpecialPlanId") as HiddenField;
            Repeater rep = e.Item.FindControl("rptNoVerifySpecialPlanDetail") as Repeater;//找到里层的repeater对象
            Label lblAlert = e.Item.FindControl("lblAlert") as Label;
            Button btnDownLoad = e.Item.FindControl("btnDownLoad") as Button;
            HiddenField HAttachmengPath = e.Item.FindControl("HAttachmengPath") as HiddenField;
            HiddenField HState = e.Item.FindControl("HState") as HiddenField;
            HiddenField HEvaluatePeopleVerifyOpinion = e.Item.FindControl("HEvaluatePeopleVerifyOpinion") as HiddenField;
            
            TextBox tb_txtVerifyPeopleOpinion = e.Item.FindControl("txtVerifyPeopleOpinion") as TextBox;
            if (HAttachmengPath.Value.Length > 0)
            {
                lblAlert.Visible = false;
                btnDownLoad.Visible = true;
            }
            else
            {
                lblAlert.Visible = true;
                btnDownLoad.Visible = false;
            }

            tb_txtVerifyPeopleOpinion.Text = HEvaluatePeopleVerifyOpinion.Value;
            if (Convert.ToInt32(HState.Value) == 2)
            {
                tb_txtVerifyPeopleOpinion.Attributes.Add("readonly", "true");
            }
            else
            {
                tb_txtVerifyPeopleOpinion.Enabled = true;
            }

            


            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(HSpecialPlanId.Value);
            rep.DataSource = new BLL.SpecialPlan().GetSpecialPlanDetailBySpecialId(_value);
            rep.DataBind();


        }
    }


    /// <summary>
    /// 待审核Reapeater绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptNoVerifySpecialPlanDetail_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField HSpecialPlanDetailId = e.Item.FindControl("HSpecialPlanDetailId") as HiddenField;
            HiddenField HState = e.Item.FindControl("HState") as HiddenField;
            HiddenField HEvaluatePeopleVerifyOpinion = e.Item.FindControl("HEvaluatePeopleVerifyOpinion") as HiddenField;
            HiddenField HVerifyPeople = e.Item.FindControl("HVerifyPeople") as HiddenField;
            HiddenField HEvaluatePeople = e.Item.FindControl("HEvaluatePeople") as HiddenField;
            Button btnPass = e.Item.FindControl("btnPass") as Button;
            Button btnNopass = e.Item.FindControl("btnNoPass") as Button;
            TextBox tb_txtVerifyPeopleOpinion = e.Item.FindControl("txtVerifyPeopleOpinion") as TextBox;
            tb_txtVerifyPeopleOpinion.Text = HEvaluatePeopleVerifyOpinion.Value;
            if (Convert.ToInt32(HState.Value) == 2)
            {
                tb_txtVerifyPeopleOpinion.Attributes.Add("readonly", "true");
            }
            else
            {
                tb_txtVerifyPeopleOpinion.Enabled = true;
            }
            DataTable dt = new BLL.UserInfoManager().get(BLL.UserInfoManager.field.UserName.ToString(), new object[] { objUserInfo.UserName });
            btnPass.Enabled = false;
            btnNopass.Enabled = false;

            if (objUserInfo.UserName == HVerifyPeople.Value && Convert.ToInt32(HState.Value) == 2)
            {
                btnPass.Enabled = true;
                btnNopass.Enabled = true;
            }

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["RealName"].ToString() == HEvaluatePeople.Value && Convert.ToInt32(HState.Value) == 1)
                {
                    btnPass.Enabled = true;
                    btnNopass.Enabled = true;
                }
            }
        }
    }

    protected void rptNoVerifySpecialPlan_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }

    protected void rptNoVerifySpecialPlanDetail_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Pass")
        {
            Repeater rpt = source as Repeater;

            object[] _user = new object[1];
            _user[0] = objUserInfo.UserName;
            DataTable _userTable = new BLL.UserInfoManager().get(UserInfoManager.field.UserName.ToString(), _user);

            if (_userTable.Rows.Count > 0)
            {
                int _count = 0;
                List<object[]> _valueList = new List<object[]>();
                object[] _username = new object[2];

                foreach (RepeaterItem i in rpt.Items)
                {
                    CheckBox cbox = (CheckBox)i.FindControl("ckbSelect");
                    if (cbox.Checked == true)
                    {
                        object[] _value = new object[3];
                        _value[0] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanDetailId")).Value);
                        _value[1] = objUserInfo.UserName;
                        //主管领导不需要修改审核意见
                        _username[0] = _userTable.Rows[0]["RealName"].ToString();
                        _username[1] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanDetailId")).Value);
                        DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanDetailById(new object[] { _value[0] });
                        TextBox tb = (TextBox)i.FindControl("txtVerifyPeopleOpinion");
                        if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() != _userTable.Rows[0]["RealName"].ToString())
                        {
                            _value[2] = "";
                        }
                        else
                        {
                            if (tb.Text.Length < 18)
                            {
                                Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                                return;
                            }
                            _value[2] = tb.Text;
                        }
                        _valueList.Add(_value);
                        _count++;
                    }
                }

                if (_count == 0)
                {
                    Utility.HttpHelp.alert("请至少选择一个专项计划", Page);
                    return;
                }
                if (this.drpType.SelectedItem.Text != null && this.drpType.SelectedItem.Value == "1")
                {
                    //修改发送状态为2，进入审核流程
                    int result = new BLL.SpecialPlan().EditSpecialPlanDetailOkByIdWithTranscation(_valueList);
                    if (result == 0)
                    {
                        Utility.Error.RedirectErrorPage("提交计划评估未成功，请重试！");
                    }
                    else
                    {
                        Response.Redirect("NoVerifySpecialPlan.aspx");
                    }
                }
            }
        }
        if (e.CommandName == "NoPass")
        {//根据评估人查询当前用户的待审专项计划
            //判断是否评估人
            object[] _user = new object[1];
            _user[0] = objUserInfo.UserName;
            DataTable _userTable = new BLL.UserInfoManager().get(UserInfoManager.field.UserName.ToString(), _user);
            Repeater rpt = source as Repeater;

            if (_userTable.Rows.Count > 0)
            {
                int _count = 0;
                List<object[]> _valueList = new List<object[]>();
                object[] _username = new object[2];

                foreach (RepeaterItem i in rpt.Items)
                {
                    CheckBox cbox = (CheckBox)i.FindControl("ckbSelect");
                    if (cbox.Checked == true)
                    {
                        object[] _value = new object[2];
                        _value[0] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanDetailId")).Value);
                        //主管领导不需要修改审核意见
                        _username[0] = _userTable.Rows[0]["RealName"].ToString();
                        _username[1] = Convert.ToInt32(((HiddenField)i.FindControl("HSpecialPlanDetailId")).Value);
                        DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(new object[] { _value[0] });
                        TextBox tb = (TextBox)i.FindControl("txtVerifyPeopleOpinion");
                        if (SpecialPlan.Rows[0]["EvaluatePeople"].ToString() != _userTable.Rows[0]["RealName"].ToString())
                        {
                            _value[1] = SpecialPlan.Rows[0]["CheckNote"].ToString();
                        }
                        else
                        {
                            if (tb.Text.Length < 18)
                            {
                                Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                                return;
                            }
                            _value[1] = tb.Text;
                        }
                        _value[1] = tb.Text;
                        _valueList.Add(_value);
                        _count++;
                    }
                }
                if (_count == 0)
                {
                    Utility.HttpHelp.alert("请至少选择一个计划", Page);
                    return;
                }
                int result = new BLL.SpecialPlan().EditSpecialPlanDetailReturnByIdWithTranscation(_valueList);
                if (result == 0)
                {
                    Utility.Error.RedirectErrorPage("提交计划评估人评估未成功，请重试！");
                }
                else
                {
                    Response.Redirect("NoVerifySpecialPlan.aspx");
                }
            }
        }
    }
}